import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:wallet_home/tools/theme_utils.dart';

import '../image_r.dart';
import '../module_config.dart';

class WalletSliverHeaderWidget extends StatefulWidget {
  final String title;
  final double topPadding;
  String amount;
  final bool isEyeHide;
  final GlobalKey<ScaffoldState> walletKey;

  WalletSliverHeaderWidget(
      {Key key,
      this.title,
      this.topPadding,
      this.amount,
      this.isEyeHide,
      this.walletKey})
      : super(key: key);

  @override
  _WalletSliverHeaderWidgetState createState() =>
      _WalletSliverHeaderWidgetState();
}

class _WalletSliverHeaderWidgetState extends State<WalletSliverHeaderWidget> {
  String header = "";

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    header = NumUtil.getNumByValueStr(widget.amount).toStringAsFixed(2);
    return Stack(
      children: [
        Container(
            padding: EdgeInsets.only(top: 38),
            width: double.infinity,
            alignment: Alignment.topCenter,
            decoration: BoxDecoration(
                gradient: LinearGradient(
                    colors: ThemeUtils.isDark(context)
                        ? [Colors.grey[900], Colors.grey[800]]
                        : [Color(0xFF0445d1), Color(0xFF007ff3)])),
            child: Container(
                margin: EdgeInsets.only(top: widget.topPadding),
                child: Column(children: [
                  Text(
                    widget.title,
                    style: TextStyle(color: Colors.grey[200], fontSize: 14),
                  ),
                  Padding(
                      padding: EdgeInsets.only(left: 15,bottom: 10),
                      child: Text.rich(TextSpan(children: [
                        TextSpan(
                            text: header,
                            style: TextStyle(
                                color: Colors.white, fontSize: 14)),
                        TextSpan(
                            text: " CNY ",
                            style: TextStyle(
                                color: Colors.white, fontSize: 14)),
                        WidgetSpan(
                            child: Opacity(
                              opacity: widget.isEyeHide ? 0.0 : 1.0,
                              child: InkWell(
                                child: Container(
                                    margin: EdgeInsets.only(top: 3.0),
                                    child: Image.asset(ImageR.imagesEyeIcon,
                                        width: 18,
                                        height: 18,
                                        color: Colors.white,
                                        fit: BoxFit.fill,
                                        package: ModuleConfig.moduleName)),
                                onTap: () {
                                  if (header == "****") {
                                    header = widget.amount;
                                  } else {
                                    header = "****";
                                  }
                                  setState(() {});
                                },
                              ),
                            ),
                            alignment: PlaceholderAlignment.middle)
                      ]))),
                ]))),
        Padding(
            padding: EdgeInsets.only(left: 15, top: 50 + widget.topPadding / 6),
            child: InkWell(
              child: Image.asset(ImageR.imagesLeftMenuIcon,
                  width: 22,
                  height: 22,
                  color: Colors.grey[200],
                  fit: BoxFit.fill,
                  package: ModuleConfig.moduleName),
              onTap: () {
                widget.walletKey.currentState.openDrawer();
              },
            ))
      ],
    );
  }
}
